package com.clickfarm.project.cf.service.impl;

import java.util.Date;
import java.util.List;

import com.clickfarm.common.utils.ServletUtils;
import com.clickfarm.common.utils.spring.SpringUtils;
import com.clickfarm.framework.security.LoginUser;
import com.clickfarm.framework.security.service.TokenService;
import com.clickfarm.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.clickfarm.project.cf.mapper.CfNoticeMapper;
import com.clickfarm.project.cf.domain.CfNotice;
import com.clickfarm.project.cf.service.ICfNoticeService;

/**
 * 公告Service业务层处理
 * 
 * @author clickfarm
 * @date 2020-06-10
 */
@Service
public class CfNoticeServiceImpl implements ICfNoticeService 
{
    @Autowired
    private CfNoticeMapper cfNoticeMapper;

    /**
     * 查询公告
     * 
     * @param id 公告ID
     * @return 公告
     */
    @Override
    public CfNotice selectCfNoticeById(Long id)
    {
        return cfNoticeMapper.selectCfNoticeById(id);
    }

    /**
     * 查询公告列表
     * 
     * @param cfNotice 公告
     * @return 公告
     */
    @Override
    public List<CfNotice> selectCfNoticeList(CfNotice cfNotice)
    {
        return cfNoticeMapper.selectCfNoticeList(cfNotice);
    }

    /**
     * 新增公告
     * 
     * @param cfNotice 公告
     * @return 结果
     */
    @Override
    public int insertCfNotice(CfNotice cfNotice)
    {
        cfNotice.setCreateTime(new Date());
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        SysUser currentUser = loginUser.getUser();
        cfNotice.setCreater(currentUser.getUserId());
        return cfNoticeMapper.insertCfNotice(cfNotice);
    }

    /**
     * 修改公告
     * 
     * @param cfNotice 公告
     * @return 结果
     */
    @Override
    public int updateCfNotice(CfNotice cfNotice)
    {
        cfNotice.setUpdateTime(new Date());
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        SysUser currentUser = loginUser.getUser();
        cfNotice.setUpdater(currentUser.getUserId());
        return cfNoticeMapper.updateCfNotice(cfNotice);
    }

    /**
     * 批量删除公告
     * 
     * @param ids 需要删除的公告ID
     * @return 结果
     */
    @Override
    public int deleteCfNoticeByIds(Long[] ids)
    {
        return cfNoticeMapper.deleteCfNoticeByIds(ids);
    }

    /**
     * 删除公告信息
     * 
     * @param id 公告ID
     * @return 结果
     */
    @Override
    public int deleteCfNoticeById(Long id)
    {
        return cfNoticeMapper.deleteCfNoticeById(id);
    }
}
